package com.spirng.leetcode.day04;

public class String5 {
    public static void main(String[] args) {
        int[] aabaafs = creatNext("aabaaf");
        System.out.println(aabaafs);
    }
    public static int []  creatNext(String s){
        int [] next=new int[s.length()];
        int j=0;//最大公共前后缀值 前缀最大值
        int i=0;//后缀最大值
        //初始化数组
        next[0]=j;
        char[] model = s.toCharArray();
        for ( i =1 ; i < s.length(); i++) {
            //不同
            while (j>0&&model[j] != model[i]) {
                j=next[j-1];
            }
            //前缀最大值和后缀最大值相同
            if(model[j]==model[i]) j++;
            next[i]=j;
        }
        return next;
    }
}
